//
import { History } from "common/history";
import * as mvc from "common/mvc";
import * as dec from "common/decorator";
//
import * as dbtps from "../types";
import Library from "./library";
import Stage from "./stage";
import Timeline from "./timeline";
/**
 * 文档数据。
 * 聚合了库，舞台，时间轴，历史记录等数据。
 * 尽量将文档数据交给视图持有，视图再从文档数据中查找其他数据。
 */
export default class Document extends mvc.Model {
    public static toString(): string {
        return "[class dragonBones.model.Document]";
    }
    // 普通输出属性。
    // ==========================================================================================
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentFrameRateChange)
    @dec.getterSetter(true, true)
    public frameRate: number = 24;
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentVersionChange)
    @dec.getterSetter(true, true)
    public version: string = "6.0.0";
    /**
     * 输出的数据名称。（如果没有则采用文档名输出）
     */
    public name: string = "";
    // 发布输出属性。
    // ==========================================================================================
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentBackgroundColorChange)
    @dec.getterSetter(true, true)
    public backgroundColor: number = 0xFFFFFF;
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentSizeChange)
    @dec.getterSetter(true, true)
    public width: number = 800;
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentSizeChange)
    @dec.getterSetter(true, true)
    public height: number = 600;
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentAuthorChange)
    @dec.getterSetter(true, true)
    public author: string = "";
    @dec.addHistoryAndNotification(true, dbtps.MNotificationType.DocumentDescriptionChange)
    @dec.getterSetter(true, true)
    public description: string = "";
    // 其他属性。
    // ==========================================================================================
    /**
     * 文档在应用生命周期内的唯一标识。
     */
    public readonly id: string = new Date().getTime().toString();
    /**
     * 存储地址。
     */
    public pathURI: string = "";
    /**
     * 文档名称。（与文件名保持一致，不含后缀，运行时无法修改）
     */
    public title: string = "";
    /**
     * 历史记录。
     */
    public readonly history: History = History.create(History);
    /**
     * 库。
     */
    public readonly library: Library = Library.create(Library);
    /**
     * 舞台。
     */
    public readonly stage: Stage = Stage.create(Stage);
    /**
     * 时间轴。
     */
    //@dec.getterSetter(true, false)
    //public timeline: Timeline = new Timeline();

    private _savedHistoryIndex: number = -1;

    public get isChanged(): boolean {
        return this._savedHistoryIndex === this.history.index;
    }

    public get isSaved(): boolean {
        return this.pathURI.length > 0 && !this.isChanged;
    }

    public get outputName(): string {
        return this.name || this.title;
    }
}